﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CIT.WMS.RM.Bll;
using CIT.WMS.Product.Bll;

namespace CIT.WMS.Product
{
    public partial class FrmTCheck : Form
    {
        public FrmTCheck()
        {
            InitializeComponent();
        }

        string _BoxCode = "";
        string _TuoCode = "";

        private void FrmTCheck_Load(object sender, EventArgs e)
        {
            InitFrm();
        }

        /// <summary>
        /// 初始化画面
        /// </summary>
        private void InitFrm()
        {
            _BoxCode = "";
            _TuoCode = "";

            txtBoxCode.Text = "";
            txtTuoCode.Text = "";
            txtBoxCode.Enabled = true;
            txtTuoCode.Enabled = true;
            areaInfo.Text = "";
            areaMsg.Text = "";

            this.txtTuoCode.Focus();
        }


        /// <summary>
        /// 箱标签输入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtBoxCode_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                if (txtTuoCode.Enabled == true)
                {
                    areaMsg.Text = "请先输入托标签";
                    txtBoxCode.Text = "";
                    _BoxCode = "";
                    return;
                }

                _BoxCode = txtBoxCode.Text;
                string[] strBox = _BoxCode.Split(',');

                if (strBox.Length != 6)
                {
                    areaMsg.Text = "箱标签格式错误，请确认";
                    txtBoxCode.Text = "";
                    _BoxCode = "";
                    return;
                }
                string s1 = "料号：" + strBox[0] + "\r\n";
                string s2 = "数量：" + strBox[1] + "\r\n";
                string s3 = strBox[2];
                string s4 = "日期：" + strBox[3];
                string s5 = strBox[4];
                string s6 = strBox[5];
                areaInfo.Text = s1 + s2 + s4;

                string msg = "";
                if (IsExists(_TuoCode, _BoxCode))
                {
                    _TuoCode = txtTuoCode.Text;
                    msg = "验证成功";
                }
                else
                {
                    msg = "验证失败,请检查托标签";

                }
                txtBoxCode.Text = "";
                areaMsg.Text = msg;
            }
        }

        /// <summary>
        /// 托标签输入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtTuoCode_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                _TuoCode = txtTuoCode.Text;
                string[] strTuo = _TuoCode.Split(',');

                if (strTuo.Length != 7)
                {
                    areaMsg.Text = "托标签格式错误，请确认";
                    txtTuoCode.Text = "";
                    _TuoCode = "";
                    return;
                }

                txtTuoCode.Enabled = false;
                txtBoxCode.Focus();
            }
        }

        private bool IsExists(string fatp, string box)
        {
            string strFlexSQL = string.Format(@"select PalletNo from wms_T_Fatp where FatpCode =  '{0}' and BoxCode = '{1}' and DelFlag = 0", fatp, box);

            DataTable dt = Utils.NMS.QueryDataTable(Utils.uContext, strFlexSQL, new CIT.WMS.MESWcf.CmdParameter[0]);
            return dt.Rows.Count > 0;
        }

        /// <summary>
        /// 重置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnReset_Click(object sender, EventArgs e)
        {
            InitFrm();
        }

 

        //END

    }
}